<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      table {
        border-collapse: collapse;
      }
      th,
      td {
        border-collapse: collapse;
        border: 1px solid #333;
        text-align: center;
        display: inline-block;
        height: 40px;
        width: 100px;
        line-height: 40px;
      }
      th{
        background-color: #999;
      }
      /* table {
        width: 600px;
        text-align: center;
        margin: 0 auto;
      }

      table,
      th,
      td {
        border: 1px solid #ccc;
        border-collapse: collapse;
      }

      caption {
        font-size: 18px;
        margin-bottom: 10px;
        font-weight: 700;
      }

      tr {
        height: 40px;
        cursor: pointer;
      }

      table tr:nth-child(1) {
        background-color: #ddd;
      }

      table tr:not(:first-child):hover {
        background-color: #eee;
      } */
    </style>
  </head>
  <body>
    <table>
      <tr>
        <th>姓名</th>
        <th>年龄</th>
        <th>性别</th>
        <th>销售额</th>
        <th>销售状态</th>
      </tr>
      <!-- <tr>
        <td>${sales[i].name}</td>
        <td>${sales[i].age}</td>
        <td>${sales[i].gender}</td>
        <td>${sales[i].money}</td>
        <td>${sales[i].status}</td>
      </tr> -->

      <script>
        // 销售人员数据
        let sales = [
          { name: '小明', age: 18, gender: '男', money: 30, status: 0 },
          { name: '小红', age: 26, gender: '女', money: 99, status: 3 },
          { name: '小刚', age: 19, gender: '男', money: 88, status: 2 },
          { name: '小丽', age: 20, gender: '女', money: 67, status: 1 },
          { name: '晓强', age: 23, gender: '女', money: 77, status: 1 },
          { name: '小张', age: 25, gender: '女', money: 80, status: 2 },
        ]
        function getSort(arr = []){
                  // 冒泡排序
        for (let i = 0; i <= arr.length - 1; i++) {
          for (let j = 0; j < arr.length - 1 - i; j++) {
            // console.log(arr[j].money);
            if (arr[j].money < arr[j + 1].money) {
              let temp = arr[j]
              arr[j] = arr[j + 1]
              arr[j + 1] = temp
            }
          }
          // console.log(arr[i].money);
        }
        // console.log(arr)
        // 0:代表 未及格 1: 代表 及格 2: 代表 良好 3: 代表 优秀 //定义销售状态
        let obj = ['未及格','及格','良好','优秀']
        for (let i = 0; i < arr.length; i++) {
          let num = arr[i].status
          document.write(`
        <tr>
        <td>${arr[i].name}</td>
        <td>${arr[i].age}</td>
        <td>${arr[i].gender}</td>
        <td>${arr[i].money}万</td>
        <td>${obj[num]}</td>
        </tr>
          `)
        }
        }
        // 调用函数
        getSort(sales)
      </script>

    </table>
  </body>
</html>
